#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        std::cerr << "fork error" << std::endl;
        exit(1);
    }
    else if(pid == 0)
    {
        std::cout << "子进程：" << getpid() << "正在运行" << std::endl;
        exit(0);
    }
    else
    {
        std::cout << "父进程：" << getpid() << "等待子进程结束" << std::endl;
        sleep(10); // 先让子进程结束
        std::cout << "父进程：" << getpid() << "结束" << std::endl;
    }

    return 0;
}
